home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-05-11 | 5.2 KB | 225 lines | [TEXT/nX^n] |
- /*windowhelp.h */
- #include "TextEdit.h"
-
- #ifndef WINDOWHELP_H
- #define WINDOWHELP_H
-
- /* window add-on structure */
-
- #define WindowStruct struct w_struct
- WindowStruct
- {
- WindowRecord wr; /* the original window record */
- uchar mtop; /* margin indents */
- uchar mleft;
- uchar mbottom;
- uchar mright;
- Rect cursrt; /* rectangle used for cursor control */
- Rect zoomrt; /* rectangle for zoom operation */
- char mouser; /* mouse pointer id (cursor shape) */
- char changed; /*if window contents havebeen changed */
- short ckind; /* kind of contents */
- TEHandle curtext; /* handle to current text record for window */
- };
-
-
- #define Woffset 18
- #define SBarWidth 15
-
- /* these definitions allow easy generation of the four square
- * cornered titled windows. The basic (simplest) window is the
- * WDOC (NoGrowDocProc). To this optionally add WGROW to add a
- * grow box and/or WZOOM to add a zoom box.
- */
- #define WDOC 4
- #define WGROW -4
- #define WZOOM 8
- #define WVBAR 16
- #define WHBAR 32
-
- /* specify the content of the window */
- #define CDRAW 1
- #define CTEXT 2
-
- /* Value placed in windowKind field of WindowRecord by WindowNew
- * if the window has a grow box. This is used by routines that
- * redraw the window to decide whether to draw the grow box
- * or not
- */
- #define HASGROW 9
-
- #endif
-
- WindowHelp.c
-
-
- /* windowhelp.c
- * provides some routines to aid in opening and closing
- * windows
- */
-
- #include "abc.h"
- #include "Quickdraw.h"
- #include "EventMgr.h"
- #include "WindowMgr.h"
- #include "MenuMgr.h"
- #include "windowhelp.h"
- #include "controlhelp.h"
- #include "cursorhelp.h"
-
- short w_total = 0; /* counts total number of windows opened*/
- short w_count = 0;
- /* counts number of windows actually open */
-
- WindowNew(title,percentsz,windkind,contkind)
- char *title;
- short percentsz;
- short windkind;
- short contkind;
- {
- char *thetitle;
- Rect boundsrt;
- WindowRecord *w;
- WindowStruct *ws;
- short width;
- short depth;
- short leftedge;
- short topedge;
- Rect pagesz;
- short hasscroll;
-
- hasscroll = windkind & WVBAR + WHBAR;
- /* mask out scroll bar options */
- windkind &= 8;
- if (title)
- thetitle = title;
- else
- thetitle = "Untitled";
- SetRect(&boundsrt, screenBits.bounds.left + 4,
- screenBits.bounds.top + 24,
- screenBits.bounds.right - 4,
- screenBits.bounds.bottom - 4);
- width = boundsrt.right - boundsrt.left;
- depth = boundsrt.bottom - boundsrt.top;
- AdjustRect(&boundsrt,
- topedge = 30 + Woffset * w_total,
- leftedge = 30 + Woffset * w_total,
- ((depth * percentsz) / 100) - topedge,
- ((width * percentsz) / 100) - leftedge);
- ws = (WindowStruct *)NewPtr(sizeof (WindowStruct));
- w = (WindowRecord *)NewWindow(ws,&boundsrt,CtoPstr(thetitle),True,
- windkind,(WindowPtr)-1,True,0);
- ws = (WindowStruct *)w;
- switch (windkind)
- {
- case documentProc :
- case zoomDocProc :
- w->windowKind = HASGROW;
- break;
- };
- if (w->windowKind == HASGROW) /* set window margins */
- {
- ws->mright = ws->mbottom = SBarWidth;
- AppPage(&pagesz);
- if (hasscroll == WHBAR)
- ScrollNew(w,0,0,pagesz.right,HORZ);
- if (hasscroll == WVBAR)
- ScrollNew(w,0,0,pagesz.bottom,VERT);
- DrawControls(w);
- DrawGrowIcon(w);
- }
- else
- ws->mright = ws->mbottom = 0;
- ws->mtop = ws->mleft = 0;
- ws->changed = FALSE;
- ws->ckind = contkind;
- ws->curtext = NIL;
- SetCursorRect(w); /* set the cursor rectangle for cursor control */
- AppNew(w); /* function to open application structure */
- w_count++;
- w_total++;
- PtoCstr(thetitle);
- }
-
- /* WindowClose()
- * Closes the window passed to it. Assumes window was opened
- * with WindowNew(). If the window is a desk accessory, it will
- * be closed correctly. If it is an application window, prior
- * to the window close there is a call to AppClose() (which
- * the application must supply) to allow any application
- * specific closing.
- */
- WindowClose(w)
- WindowRecord *w;
- {
- WindowStruct *ws;
- short refnum;
-
- if (ws = (WindowStruct *)w)
- if ((refnum = w->windowKind) < 0)
- CloseDeskAcc(refnum);
- else
- {
- AppClose(w); /* close app storage, must do before */
- CloseWindow(w); /* CloseWindow */
- DisposPtr(w);
- w_count--; /* decrement the window count */
- if (w_count == 0)
- /* if the number of windows on screen goes to */
- w_total = 0;
- /* zero, set total to zero so next time we */
- } /* open a window it will start at the original */
- } /* window position */
-
- /* AdjustRect
- * adjusts coordinates of a rectangle by four separate
- * amounts. adjustment is in (towards center) if amounts are
- * positive and out if amounts are negative);
- */
- AdjustRect(rec,t,l,b,r)
- Rect *rec;
- short t,l,b,r; /* values to adjust rectangle by */
- {
- rec->top +=t;
- rec->left += l;
- rec->bottom -= b;
- rec->right -= r;
- }
-
- /* RtGlobalToLocal
- * Adjusts a rectangle to local coordinates
- */
- RtGlobalToLocal(rt)
- Rect *rt;
- {
- Point *pt;
-
- pt = (Point *)rt;
- GlobalToLocal(pt);
- pt++;
- GlobalToLocal(pt);
- }
-
-
-
- dofile(item)
- short item;
- {
- WindowRecord *w;
-
- switch(item)
- {
- case iNew : WindowNew("",40,WDOC+WGROW+WVBAR,CTEXT);
- break;
- case iClose : WindowClose(FrontWindow());
- break;
- case iQuit : while (w = (WindowRecord *)FrontWindow() )
- {
- WindowClose(w);
- }
- ExitToShell();
- break;
- }
- }
-
-